package ext.load;

import ext.trace.camera.CameraPinhole;
import ext.trace.geom.BRDF;
import ext.trace.geom.Geom;
import ext.trace.geom.LambertBRDF;
import ext.trace.scene.Scene;
import image.Image3;
import image.disk.FormatPNG;
import math.region.Cylinder3;
import math.region.Plane3;
import math.region.Rect3;
import math.region.Sphere3;
import math.region.Tri3;
import math.vec3;

public class DataGeom
{
    
    public static void load0(Scene aScene)
    {
        Geom g;
        Rect3 r;
        Sphere3 s;
        Cylinder3 c;
        Plane3 p;
        Tri3 t;
        
        Image3 i1 = FormatPNG.load("image/checker");
        Image3 i2 = FormatPNG.load("image/red");
        Image3 i3 = FormatPNG.load("image/green");
        Image3 i4 = FormatPNG.load("image/blue");
        Image3 i5 = FormatPNG.load("image/white");
        
        double wallKd = 0.8;
        double wallKs = 0.0;
        double wallRAng = 16.0;
        BRDF wallBRDF = new LambertBRDF();
        wallBRDF.rAlbedo = i5;
        
        double sphereKd = 0.8;
        double sphereKs = 0.0;
        double sphereRAng = 8.0;
        BRDF sphereBRDF = new LambertBRDF();
        sphereBRDF.rAlbedo = i5;
        
        double triKd = 0.8;
        double triKs = 0.0;
        double triRAng = 8.0;
        
//        g = new Geom();
//        s = new Sphere3();
//        s.mOrig.set(0, 0, 0);
//        s.mRadius = 3;
//        g.rSurf0 = s.copy();
//        g.rSurf1 = s.copy();
//        g.mMat.mRadExit = 0;
//        g.mMat.mKd = sphereKd;
//        g.mMat.mKs = sphereKs;
//        g.mMat.mReflAngle = sphereRAng;
//        g.mMat.rBRDF = sphereBRDF.copy();
//        g.mMat.rBRDF.rAlbedo = i5;
//        aScene.add(g);
        
        g = new Geom();
        r = new Rect3();
        r.mOrig.set(-2, 7.8, -2);
        r.mA.set(4, 0, 0);
        r.mB.set(0, 0, 4);
        g.rSurf0 = r.copy();
        g.rSurf1 = r.copy();
        g.mMat.mRadExit = 1.0 / r.surfaceArea();
        g.mMat.mKd = 1;
        g.mMat.mKs = 0;
        g.mMat.mReflAngle = 0;
        g.mMat.rBRDF = new LambertBRDF();
        g.mMat.rBRDF.rAlbedo = i5;
        aScene.add(g);
        
        CameraPinhole cam = new CameraPinhole(); // CAMERA
        cam.setOrig(new vec3(-8, -8, 8));
        cam.setW(new vec3(16, 0, 0));
        cam.setH(new vec3(0, 16, 0));
        cam.setFocalLength(16.0);
        aScene.rCamera = cam;
        
        g = new Geom(); // Near wall
        r = new Rect3();
        r.mOrig.set(-8, -8, 8);
        r.mA.set(16, 0, 0);
        r.mB.set(0, 16, 0);
        g.rSurf0 = r.copy();
        g.rSurf1 = r.copy();
        g.mMat.mRadExit = 0;
        g.mMat.mKd = wallKd;
        g.mMat.mKs = wallKs;
        g.mMat.mReflAngle = wallRAng;
        g.mMat.rBRDF = wallBRDF.copy();
        g.mMat.rBRDF.rAlbedo = i5;
        aScene.add(g);
        
        g = new Geom(); // Far wall
        
        t = new Tri3();
        t.mOrig.set(-8, 0, -8);
        t.mA.set(8, 8, 0);
        t.mB.set(8, -8, 0);
        g.rSurf0 = t.copy();
        g.rSurf1 = t.copy();
//        r = new Rect3();
//        r.mOrig.set(-8, -8, -8);
//        r.mA.set(16, 0, 0);
//        r.mB.set(0, 16, 0);
//        g.rSurf0 = r.copy();
//        g.rSurf1 = r.copy();
        g.mMat.mRadExit = 0;
        g.mMat.mKd = wallKd;
        g.mMat.mKs = wallKs;
        g.mMat.mReflAngle = wallRAng;
        g.mMat.rBRDF = wallBRDF.copy();
        g.mMat.rBRDF.rAlbedo = i5;
        aScene.add(g);
        
        g = new Geom(); // Left wall
        r = new Rect3();
        r.mOrig.set(-8, -8, -8);
        r.mA.set(0, 16, 0);
        r.mB.set(0, 0, 16);
        g.rSurf0 = r.copy();
        g.rSurf1 = r.copy();
        g.mMat.mRadExit = 0;
        g.mMat.mKd = wallKd;
        g.mMat.mKs = wallKs;
        g.mMat.mReflAngle = wallRAng;
        g.mMat.rBRDF = wallBRDF.copy();
        g.mMat.rBRDF.rAlbedo = i2;
        aScene.add(g);
        
        g = new Geom(); // Right wall
        r = new Rect3();
        r.mOrig.set(8, -8, -8);
        r.mA.set(0, 16, 0);
        r.mB.set(0, 0, 16);
        g.rSurf0 = r.copy();
        g.rSurf1 = r.copy();
        g.mMat.mRadExit = 0;
        g.mMat.mKd = wallKd;
        g.mMat.mKs = wallKs;
        g.mMat.mReflAngle = wallRAng;
        g.mMat.rBRDF = wallBRDF.copy();
        g.mMat.rBRDF.rAlbedo = i3;
        aScene.add(g);
        
        g = new Geom(); // Bottom wall
        r = new Rect3();
        r.mOrig.set(-8, -8, -8);
        r.mA.set(16, 0, 0);
        r.mB.set(0, 0, 16);
        g.rSurf0 = r.copy();
        g.rSurf1 = r.copy();
        g.mMat.mRadExit = 0;
        g.mMat.mKd = wallKd;
        g.mMat.mKs = wallKs;
        g.mMat.mReflAngle = wallRAng;
        g.mMat.rBRDF = wallBRDF.copy();
        g.mMat.rBRDF.rAlbedo = i5;
        aScene.add(g);
        
        g = new Geom(); // Top wall
        r = new Rect3();
        r.mOrig.set(-8, 8, -8);
        r.mA.set(16, 0, 0);
        r.mB.set(0, 0, 16);
        g.rSurf0 = r.copy();
        g.rSurf1 = r.copy();
        g.mMat.mRadExit = 0;//1.0 / r.surfaceArea();
        g.mMat.mKd = wallKd;
        g.mMat.mKs = wallKs;
        g.mMat.mReflAngle = wallRAng;
        g.mMat.rBRDF = wallBRDF.copy();
        g.mMat.rBRDF.rAlbedo = i5;
        aScene.add(g);
        
    }
    
}
